#ifndef BASEDEDATOS_H_
#define BASEDEDATOS_H_
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <set>
#include <sstream>
#include "VectorFourier.h"
#include <cmath>

using namespace std;

class par_vector{
public:
	int x;
	int y;
	par_vector(int a,int b);
	par_vector();
	inline bool operator<(const par_vector& un_par_vector) const {
		if(this->x > un_par_vector.x)
			return false;
		if(this->x < un_par_vector.x)
			return true;
		if(this->x == un_par_vector.x){
			if(this->y < un_par_vector.y)
				return true;
			else
				return false;
		}
	return false;
		
    }
	inline bool operator==(const par_vector& un_par_vector) const {
		if(this->x == un_par_vector.x && this->y == un_par_vector.y)
			return true;
		if(this->x == un_par_vector.y && this->y == un_par_vector.x)
			return true;
		return false;

	}
};


/*class distancia_pares{
public:
	par p;
	double d;
public:
	distancia_pares(int a,int b, double d);
	
};*/


class BaseDeDatos{

private:
	map<par_vector,float> indice_distancias;
	map<par_vector,float> tabla_pivotes;
	
	set<int> pivotes;
	float distancia_maxima;
	int cant_pivotes;
	par_vector mas_lejanos;

	fstream fmetadata;
	fstream findice;
	fstream fdatos;
	fstream fpivotes;
	int last_id_encabezado;
	stringstream aux_datos;

private:	
	int distancia_R;
	void escribir_metadata();
	void leer_metadata();
public:
	BaseDeDatos();
	BaseDeDatos(int distancia_R);
	~BaseDeDatos(){};
	void abrir();
	void cerrar();
	void Agregar(string nombre_archivo,string datos);
	string Leer(int id);
	string obtenerNombre(int id);
	void calcularDistancias();
	void almacenarDistancia(int i, int j, float d);
	void elegirPivotes();
	void persistirPivotes();
	void cargarPivotes();
	multimap<float,string> buscarSimilar(VectorFourier query);
	
};


#endif